import {ElMessage} from 'element-plus';
import {BellFilled} from "@element-plus/icons-vue"

const baseOpitons = {
  type:'primary',
  message:"",
  duration: 2000,
  plain:true,
  offset:16,
  grouping:false
}
/**
 * 二次封装ElMessage
 * @param {*} option 
 * @param {*} option.type
 * @param {*} option.message
 * @param {*} option.duration
 * @param {*} option.offset
 * @param {*} option.grouping
 * @returns 
 */
function baseMessage(options = baseOpitons) {
  if (typeof options === 'string') {
    options = { message: options }
  }
  options = Object.assign({}, baseOpitons, options)
  // icon
  if(typeof options === 'object' && options.type === 'primary'){
    options.icon = BellFilled
  }
  return ElMessage(options)
}
const types = ['primary','success', 'warning', 'info', 'error']
types.forEach((type) => {
  baseMessage[type] = (msg, option = baseOpitons) => {
    if (typeof msg === 'string') {
      option.message = msg
    } else {
      option = msg || baseOpitons
      if(type === 'primary'){
        option.icon = BellFilled
      }
    }

    return baseMessage({
      ...option,
      type,
    })
  }
})
export const message = baseMessage

